package com.qmgyl.marketshop.product.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qmgyl.marketshop.common.ResponseJsonUtils;

import util.JsonUtil;
import util.Page;

@Controller
@RequestMapping(value = "/productclass")
public class ProductClassController {
 
	
	@RequestMapping(value="/{name}", method = RequestMethod.GET)
	public String data(@PathVariable("name") String name){
		return name;
	}
	 



	/**
	 * 商品分类list
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	@RequestMapping(value="getList")
	@ResponseBody
	public void getList(Integer page,Integer rows,String ssuName,String className, HttpServletRequest request, HttpServletResponse response) throws IOException{
		
		List<Object> list = new ArrayList<>();
		list.clear();
		for(int i=1;i<4;i++){
			Map<String, Object> data = new HashMap<String, Object>();
			
			data.put("id",i);
			data.put("ut", 1458806819);
			data.put("name", "蔬菜"+i); 
			data.put("parentId", 0);
			list.add(data);
			
			for(int k=11;k<14;k++){
				Map<String, Object> datas = new HashMap<String, Object>();
				
				datas.put("id",k+i);
				datas.put("ut", 1458806819);
				datas.put("name", "叶菜类"+k+i); 
				datas.put("parentId", i);
				list.add(datas);
				
			}
		}
		 
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("rows");
		System.out.println("page:"+currentPage);
		System.out.println("pageSize:"+pageSize);
		
		Page pages=new Page();
		pages.setResultList(list);
		pages.setStart((page-1)*rows);
		pages.setTotalSize(12);
		pages.setPageSize(rows);
		String json = JsonUtil.getJsonStringFromPage(pages, "yyyy-MM-dd");
		response.setContentType("text/html;charset=UTF-8");
		response.getWriter().write(json);
	}
	
	
	/**
	 * 商品分类
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	@RequestMapping(value="getClassList")
	@ResponseBody
	public void getClassList(String pClassId, HttpServletRequest request, HttpServletResponse response) throws IOException{
		
		List<Object> list = new ArrayList<>();
		list.clear();
		for(int i=1;i<4;i++){
			Map<String, Object> data = new HashMap<String, Object>();
			
			data.put("classId",i);
			data.put("ut", 1458806819);
			data.put("className", "蔬菜"+i); 
			data.put("parentId", 0);
			list.add(data);
			 
		}
		 
	 
		ResponseJsonUtils.json(response, list);
		 
		 
	}
}
